package com.sort;

import java.util.Arrays;
import java.util.Random;

public class SortTest {
	public static void main(String[] args) {
		int[] is = {9,8,7,6,5,4,3,2,1};
		is = getRandomInts();
		System.out.println(Arrays.toString(is));
		insertSort(is);
		System.out.println(Arrays.toString(is));
		bubbleSort(is);
		System.out.println(Arrays.toString(is));
		
	}
	public static void insertSort(int[] is){
		
		for (int i = 1; i < is.length; i++) {
			int vali = is[i];
			for (int j = i-1; j >=0; j--) {
				
				if(is[j] > vali){
					is[j+1] = is[j];
					is[j] = vali;
				}
			}
		}
		
	}
	
	public static void bubbleSort(int is[]){
		
		for (int i = 0; i < is.length; i++) {
			for (int j = 1; j < is.length - i; j++) {
				if(is[j-1] > is[j]){
					int temp = is[j];
					is[j] = is[j-1];
					is[j - 1] = temp;
				}
			}
		}
		
	}
	
	public static int[] getRandomInts(){
		Random r = new Random();
		int length = r.nextInt(100) + 10;
		int is[]  =  new int[length];
		for (int i = 0; i < length; i++) {
			is[i] = r.nextInt(10000);
		}
		return is;
	}
}
